package com.example.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class InternalPage extends AnyPage {
// Main Page with menu
	//@FindBy(linkText = "Log out")
	//@FindBy(xpath = "//a[@href='http://localhost/php4dvd/?go=logout']")
    @FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[4]/a")
	public static WebElement menuLogoutLink;

	//@FindBy(linkText = "User management")
	//@FindBy(xpath = "//a[@href='http://localhost/php4dvd/?go=users']")
    @FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[3]/a")
	public WebElement menuUserManagementLink;
    
    //@FindBy(linkText = "My profile")
	//@FindBy(xpath = "//a[@href='http://localhost/php4dvd/?go=profile']")
    @FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[2]/a")
	public WebElement menuMainProfileLink;

    //@FindBy(linkText = "Home")
	//@FindBy(xpath = "//a[@href='http://localhost/php4dvd/']")
    @FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li/a")
	public WebElement menuHomeLink;
    
	public boolean IsOnThisPage()	{
	return menuLogoutLink.isDisplayed() ;
	}
	
    public void logout() {
	    menuLogoutLink.click();
	    wait_().until(alertIsPresent()).accept();
	}
    
    public UserPage gotoUserManagementConsole() {
    	menuUserManagementLink.click();
		return MyPageFactory.getPage(driver, UserPage.class);
    	
    }
	
	@Override
	public void tryToOpen() {
		MyPageFactory.getPage(driver, LoginPage.class).loginWithValidCredentials("admin", "admin");
	}
	
}
